package com.itheima.test12;

import java.math.BigDecimal;

/*
有以下学员信息：
		张三,男,20,79.5
		李四,女,21,80.2
		王五,男,22,77.9
		周六,男,20,55.8
		赵七,女,21,99.9
	请定义学员类，属性：姓名、性别、年龄、分数
	请编写测试类，创建5个对象，分别存储上述值，并计算5名学员的“平均分”(四舍五入到小数点后2位)。
 */
public class Test12 {
    public static void main(String[] args) {
        BigDecimal sum = new BigDecimal("0.00");
        Student zhangsan = new Student("张三", "男", "20", "79.5");
        Student lisi = new Student("李四", "女", "21", "80.2");
        Student wangwu = new Student("王五", "男", "22", "77.9");
        Student zhouliu = new Student("周六", "男", "20", "75.8");
        Student zhaoqi = new Student("赵七", "女", "21", "99.9");
        sum = getSum(sum, zhangsan);
        sum = getSum(sum, lisi);
        sum = getSum(sum, wangwu);
        sum = getSum(sum, zhouliu);
        sum = getSum(sum, zhaoqi);
        System.out.println("总值为：" + sum);
        System.out.println("平均分为" + sum.divide(new BigDecimal("5"),4));
    }

    private static BigDecimal getSum(BigDecimal sum, Student zhangsan) {
        BigDecimal bigDecimal = new BigDecimal(zhangsan.getResult());
        BigDecimal res = sum.add(bigDecimal);
        return res;
    }
}
